#!/usr/bin/env bash

if [ -z "$WM_PROJECT" ]; then
  echo "OpenFOAM environment not found, forgot to source the OpenFOAM bashrc?"
  exit 1
fi

case $1 in
  "opt")
    cp setup_Incompressible.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ./Allclean
    cp setup_Compressible.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ./Allclean
    cp setup_Solid.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ;;
  "debug")
    cp setup_Incompressible.py setup.py
    sed -i 's/"-std=c++11",/"-std=c++11","-DFULLDEBUG -g -O0",/g' setup.py
    python setup.py build_ext --inplace  || exit 1
    mv *.so ../../dafoam
    ./Allclean
    cp setup_Compressible.py setup.py
    sed -i 's/"-std=c++11",/"-std=c++11","-DFULLDEBUG -g -O0",/g' setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ./Allclean
    cp setup_Solid.py setup.py
    sed -i 's/"-std=c++11",/"-std=c++11","-DFULLDEBUG -g -O0",/g' setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ;;
  "incompressible")
    cp setup_Incompressible.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ;;
  "compressible")
    cp setup_Compressible.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ;;
  "solid")
    cp setup_Solid.py setup.py
    python setup.py build_ext --inplace || exit 1
    mv *.so ../../dafoam
    ;;
  *)
    echo "Argument not valid! Options are: opt, debug, incompressible, compressible, or solid"
    echo "Example: ./Allmake opt"
    exit 1
    ;;
esac


